﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetFrameworkExtensions.Enterprise.Properties;

namespace NetFrameworkExtensions.Enterprise.Security
{
  public sealed class EntityAuthorizableOperation :
    AuthorizableOperation<EntityAuthorizableOperation>
  {
    internal EntityAuthorizableOperation(string entityName, AuthorizableOperationKind kind)
      : base(entityName, kind)
    {
      switch (kind)
      {
        case AuthorizableOperationKind.Read:
        case AuthorizableOperationKind.Update:
        case AuthorizableOperationKind.Create:
        case AuthorizableOperationKind.Delete:
          break;
        default:
          throw new ArgumentOutOfRangeException("kind");
      }
    }

    public override string ToString()
    {
      switch (Kind)
      {
        case AuthorizableOperationKind.Read:
          return FormattedResources.ReadEntity(Name);
        case AuthorizableOperationKind.Update:
          return FormattedResources.UpdateEntity(Name);
        case AuthorizableOperationKind.Create:
          return FormattedResources.CreateEntity(Name);
        case AuthorizableOperationKind.Delete:
          return FormattedResources.DeleteEntity(Name);
      }
      throw new NotSupportedException();
    }

    public override string EntityName
    {
      get { return Name; }
    }
  }
}
